
const modules = import.meta.glob('/src/view/**/*.vue')

// 加载组件
function loadComponent(componentPath) {
  const fullPath = `/src/view/${componentPath}.vue`
  return modules[fullPath] || modules['/src/view/404.vue']
}


/**
 * 将后端权限菜单转为 Vue Router 动态路由
 * @param {Array} menuList 后端返回的权限菜单树
 * @returns {Array} RouteRecordRaw[]
 */
export function buildMenuTree(menuList) {
  return menuList
    .filter(item => item.permissionResourcetype === 'menu')
    .map(item => {
      console.log("1====>",item.opFlag === "1")
      const route = {
        path: '/' + item.url,
        name: item.permissionName,
        component: loadComponent(item.url),
        meta: {
          title: item.permissionName,
          id: item.permissionId,
          hidden: item.opFlag === "1" ? true : false
        }
      }

      // 如果是父节点，component 固定使用 index.vue
      if (item.children && item.children.length > 0) {
        route.component = () => import('@/index.vue')
        route.children = buildMenuTree(item.children)
      }

      return route
    })
}

